package com.glory.wxelectricitypda.activity;


import android.os.Handler;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.glory.wxelectricitypda.R;
import com.glory.wxelectricitypda.base.BaseDialogActivity;
import com.glory.wxelectricitypda.bean.ResponseBean;
import com.glory.wxelectricitypda.utils.FreeApi_DialogUtils;
import com.glory.wxelectricitypda.utils.NetUtils;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_ToastUtils;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


import butterknife.BindView;

public class FTExitStationActivity extends BaseDialogActivity {

    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.etLotId)
    FreeUI_ClearEditText etLotId;
    @BindView(R.id.remark)
    FreeUI_ClearEditText remark;
    @BindView(R.id.mergeBatches)
    FreeUI_ClearEditText mergeBatches;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_ftexit_station;
    }

    @Override
    protected void initView() {

        freeUI_titleView.setTitle("FT退站");
        freeUI_titleView.setRightListener("提交", new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (etLotId.getText().toString().equals("")) {
                    showToast("请扫描批次ID", false);
                    return;
                }

                submit();
            }
        });

    }

    @Override
    protected void initData() {


    }

    private void submit(){

        JSONObject jsonObject = new JSONObject();
        JSONObject jsonObject1 = new JSONObject();
        JSONArray lotList = new JSONArray();
        JSONObject lotObject = new JSONObject();
        try {
            jsonObject1.put("ACTIONTYPE","LOTFTABORT");
            jsonObject1.put("MEGERLOTID",mergeBatches.getText().toString());
            jsonObject1.put("ACTIONCOMMNT",remark.getText().toString());
            lotObject.put("LOTID",etLotId.getText().toString());
            lotList.put(lotObject);
            jsonObject1.put("LOTLIST", lotList);
//            jsonObject.put("Data", jsonObject1);
//            jsonObject.put("MessageName", "EUIT.LOTFTABORT");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        NetUtils.requestPostUtils("lotFtabort","lotFtabort",jsonObject1, this, new FreeUI_DialogEntityCallBack<ResponseBean<Object>>(
                new TypeToken<ResponseBean<Object>>() {
                }.getType(), getSupportFragmentManager(), this) {
            @Override
            public void onSuccess(Response<ResponseBean<Object>> response) {

                if (response.body().isSuccess(getApplicationContext(), false, getSupportFragmentManager())){
                    showToast("退站成功", true);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            finish();
                        }
                    }, 2000);
                }


            }

            @Override
            public void onError(Response<ResponseBean<Object>> response) {
                super.onError(response);
                loadError(response.getException(), "lotFtabort");
            }
        });

    }


    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return new FreeUI_AddViewEntity("header",llMain);
    }
}